package com.explorati.LeetCode203.removeElements;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 22:09 2020/9/20 0020
 * @ Description ：
 */
public class Solution {
    public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }

    /**
     * 删除链表中等于给定值 val 的所有节点
     * @param head
     * @param val
     * @return
     */
    public ListNode removeElements(ListNode head, int val) {
       //如果当前节点的值等于val，返回head.next; 否则返回head
        if(head == null) {
            return null;
        }

        head.next = removeElements(head.next, val);

        return head.val == val ? head.next : head;
    }
}
